package com.coin900.coin.service.coin;

import com.coin900.coin.base.CoinConstants;
import com.coin900.coin.persist.coin.CoinCoinVO;
import com.coin900.coin.persist.coin.CoinVirtualCoinVO;
import com.value.mybatis.IDaoRouter;
import com.value.mybatis.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 虚拟币
 *
 * @author shui
 * @create 2018-1-14
 */
@Service
public class CoinVirtualCoinService implements ICoinVirtualCoinService {

    @Override
    public List<CoinVirtualCoinVO> loadCoinVirtualCoin(Map<String, Object> params) {
        return this.daoRouter.query("CoinVirtualCoin.loadCoinVirtualCoin", params);
    }

    @Override
    public List<CoinVirtualCoinVO> loadCoinVirtualCoinForPage(Pagination pagination) {
        return this.daoRouter.query("CoinVirtualCoin.loadCoinVirtualCoinForPage", pagination);
    }

    @Override
    public void insertCoinVirtualCoin(CoinVirtualCoinVO coinVirtualCoinVO) {
        CoinCoinVO coinCoinVO = new CoinCoinVO();
        coinCoinVO.setType(CoinConstants.COIN_TYPE_VIRTUAL_COIN);
        coinCoinVO.setAccuracy(coinVirtualCoinVO.getAccuracy());
        coinCoinVO.setCoinName(coinVirtualCoinVO.getCoinName().toLowerCase());
        coinCoinVO.setPayforTokenStatus(0);
        coinCoinVO.setReleaseStatus(0);
        coinCoinVO.setShowInWalletStatus(0);
        coinCoinVO.setCreatedBy(coinVirtualCoinVO.getModifiedBy());
        coinCoinVO.setCreatedDate(coinVirtualCoinVO.getModifiedDate());
        coinCoinVO.setDataStatus(1);
        this.coinCoinService.insertCoinCoin(coinCoinVO);
        coinVirtualCoinVO.setCoinId(coinCoinVO.getId());
        this.daoRouter.insert("CoinVirtualCoin.insertCoinVirtualCoin", coinVirtualCoinVO);
    }

    @Override
    public void updateCoinVirtualCoin(CoinVirtualCoinVO coinVirtualCoinVO) {
        CoinCoinVO coinCoinVO = new CoinCoinVO();
        coinCoinVO.setId(coinVirtualCoinVO.getCoinId());
        coinCoinVO.setCoinName(coinVirtualCoinVO.getCoinName());
        this.coinCoinService.updateCoinCoin(coinCoinVO);
        this.daoRouter.update("CoinVirtualCoin.updateCoinVirtualCoin", coinVirtualCoinVO);
    }

    @Override
    public void deleteCoinVirtualCoin(CoinVirtualCoinVO coinVirtualCoinVO) {
        this.daoRouter.update("CoinVirtualCoin.deleteCoinVirtualCoin", coinVirtualCoinVO);
        CoinCoinVO coinCoinVO = new CoinCoinVO();
        coinCoinVO.setId(coinVirtualCoinVO.getCoinId());
        coinCoinVO.setModifiedDate(coinVirtualCoinVO.getModifiedDate());
        coinCoinVO.setModifiedBy(coinVirtualCoinVO.getModifiedBy());
        coinCoinVO.setDataStatus(0);
        this.coinCoinService.deleteCoinCoin(coinCoinVO);
    }

    @Autowired
    private ICoinCoinService coinCoinService;
    @Autowired
    private IDaoRouter daoRouter;

}